package org.example.sword2offer.primary;

/**
 * @author: lynn
 * @Descript:
 * @date: 2021/6/10 21:11
 * @version: 1.0
 */
public class Q69_TwoAscendingArray {   //fixme 两个升序数组的排列
    public static void main(String[] args) {
        int[] a = {0,1,2,3,4,5,6,6};
        int[] b = {1,2,3,4,5,6,7,8,9};
        int[] am = arrayMerge(a, b);
        for (int i=0;i < am.length;i++) { System.out.print(am[i] + " "); }
    }
    public static int[] arrayMerge(int[] a, int[] b) {
        int[] am = new int[a.length + b.length];int ai = 0;int bj = 0;
        while ((ai<a.length) && (bj<b.length)) {
            if(a[ai] < b[bj]) {
                am[ai + bj] = a[ai];
                ai++;
            } else {
                am[ai + bj] = b[bj];
                bj++;
            }
        }//判断谁剩下的比较长，加上指定长度即可
        while (ai < a.length) { am[ai + bj] = a[ai];ai++; }
        while (bj < b.length) { am[ai + bj] = b[bj];bj++; }
        return am;
    }
}
